<!DOCTYPE html>
<html>

<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>车系管理</title>
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <link rel="stylesheet" href="/plugins/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="/plugins/adminLTE/css/AdminLTE.css">
    <link rel="stylesheet" href="/plugins/adminLTE/css/skins/_all-skins.min.css">
    <link rel="stylesheet" href="/css/style.css">
    <script src="/plugins/jQuery/jquery-2.2.3.min.js"></script>
    <script src="/plugins/bootstrap/js/bootstrap.min.js"></script>

</head>

<body class="hold-transition skin-red sidebar-mini"  >
<!-- .box-body -->

<div class="box-header with-border">
    <h3 class="box-title">车辆信息管理</h3>
</div>

<div class="box-body">

    <!-- 数据表格 -->
    <div class="table-box">

        <!--工具栏-->
        <div class="pull-left">
            <div class="form-group form-inline">
                <div class="btn-group">
                    <button type="button" class="btn btn-default" title="新建" data-toggle="modal" data-target="#editModal" ><i class="fa fa-file-o"></i> 新建</button>
                    <button type="button" class="btn btn-default" title="删除" onclick="deleteBatch()"><i class="fa fa-trash-o"></i> 删除</button>
                    <button type="button" class="btn btn-default" title="开启" onclick='confirm("你确认要开启吗？")'><i class="fa fa-check"></i> 开启</button>
                    <button type="button" class="btn btn-default" title="屏蔽" onclick='confirm("你确认要屏蔽吗？")'><i class="fa fa-ban"></i> 屏蔽</button>
                    <button type="button" class="btn btn-default" title="刷新" onclick="window.location.reload();"><i class="fa fa-refresh"></i> 刷新</button>
                </div>
            </div>
        </div>

        <!--工具栏/-->

        <!--数据列表-->
        <table id="dataList" class="table table-bordered table-striped table-hover dataTable">
            <thead>
            <tr>
                <th class="" style="padding-right:0px">
                    <input id="selall" type="checkbox" class="icheckbox_square-blue">
                </th>
                <th class="sorting_asc">ID</th>
                <th class="sorting">厂商</th>
                <th class="sorting">级别</th>
                <th class="sorting">发动机</th>
                <th class="sorting">变速箱</th>
                <th class="sorting">车身结构</th>
                <th class="sorting">长宽高</th>
                <th class="sorting">轴距</th>
                <th class="sorting">行李箱容积</th>
                <th class="sorting">排量</th>
                <th class="sorting">进气形式</th>
                <th class="sorting">气缸数</th>
                <th class="sorting">最大马力</th>
                <th class="sorting">驱动方式</th>
                <th class="sorting">助力类型</th>
                <th class="sorting">驱车制动类型</th>
                <th class="sorting">胎压监制</th>
                <th class="sorting">前轮胎规格</th>
                <th class="sorting">后轮胎规格</th>
                <th class="sorting">防抱死</th>
                <th class="sorting">汽车ID</th>
                <th class="sorting">描述</th>
                <th class="text-center">操作</th>
            </tr>
            </thead>
            <tbody id="cate">

            </tbody>
        </table>
        <!--数据列表/-->
    </div>
    <!-- 数据表格 /-->
</div>
<!-- /.box-body -->
<!-- 分页 -->


<!-- 增加窗口 -->
<div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog" >
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h3 id="myModalLabel">广告分类编辑</h3>
            </div>
            <div class="modal-body">

                <tr class="table table-bordered table-striped"  width="800px">
                    <tr>
                        <td>厂商</td>
                        <td><input  class="form-control" placeholder="厂商" id="manufacturer">  </td>
                        <td>级别</td>
                        <td><input  class="form-control" placeholder="级别" id="level">  </td>
                        <td>发动机</td>
                        <td><input  class="form-control" placeholder="发动机" id="engine">  </td>
                    </tr>
                    <tr>
                        <td>变速箱</td>
                        <td><input  class="form-control" placeholder="变速箱" id="transmissionCase">  </td>
                        <td>车身结构</td>
                        <td><input  class="form-control" placeholder="车身结构" id="bodyStructure">  </td>
                        <td>长宽高</td>
                        <td><input  class="form-control" placeholder="长宽高" id="lWH">  </td>
                        <td>轴距</td>
                    </tr>
                    <tr>
                        <td><input  class="form-control" placeholder="轴距" id="wheelbase">  </td>
                        <td>行李箱容积</td>
                        <td><input  class="form-control" placeholder="行李箱容积" id="cargoVolume">  </td>
                        <td>整备质量</td>
                        <td><input  class="form-control" placeholder="整备质量" id="curbWeight">  </td>
                        <td>排量</td>
                        <td><input  class="form-control" placeholder="排量" id="displacement">  </td>
                        <td>进气形式</td>
                    </tr>
                    <tr>
                        <td><input  class="form-control" placeholder="进气形式" id="airIntakeForm">  </td>
                        <td>气缸数</td>
                        <td><input  class="form-control" placeholder="气缸数" id="numberOfCylinders">  </td>
                        <td>最大马力</td>
                        <td><input  class="form-control" placeholder="最大马力" id="maximumHorsepower">  </td>
                        <td>驱动方式</td>
                        <td><input  class="form-control" placeholder="驱动方式" id="drivingMode">  </td>
                        <td>助力类型</td>
                    </tr>
                    <tr>
                        <td><input  class="form-control" placeholder="助力类型" id="typesOfAssistance">  </td>
                        <td>驱车制动类型</td>
                        <td><input  class="form-control" placeholder="驱车制动类型" id="drivingBrakeType">  </td>
                        <td>胎压监测</td>
                        <td><input  class="form-control" placeholder="胎压监测" id="tirePressureDetection">  </td>
                        <td>前轮胎规格</td>
                    </tr>
                <tr>
                        <td><input  class="form-control" placeholder="前轮胎规格" id="frontTireSpecifications">  </td>
                        <td>后轮胎规格</td>
                        <td><input  class="form-control" placeholder="后轮胎规格" id="rearTireSize">  </td>
                        <td>防抱死</td>
                        <td><input  class="form-control" placeholder="防抱死" id="abs">  </td>
                        <td>汽车Id</td>
                        <td><input  class="form-control" placeholder="汽车Id" id="carId">  </td>
                        <td>描述</td>
                        <td><input  class="form-control" placeholder="描述" id="carDesc">  </td>
                    </tr>
                </table>

            </div>
            <div class="modal-footer">
                <button class="btn btn-success" data-dismiss="modal" aria-hidden="true" onclick="addData()">保存</button>
                <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">关闭</button>
            </div>
        </div>
    </div>
</div>
<!-- 修改窗口 -->
<div class="modal fade" id="editModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog" >
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h3 id="myModalLabel2">广告分类编辑</h3>
            </div>
            <div class="modal-body">

                <table class="table table-bordered table-striped"  width="800px">
                    <tr>
                        <input type="hidden" id="id">
                        <td>厂商</td>
                        <td><input  class="form-control" placeholder="厂商" id="manufacturer2">  </td>
                        <td>级别</td>
                        <td><input  class="form-control" placeholder="级别" id="level2">  </td>
                        <td>发动机</td>
                        <td><input  class="form-control" placeholder="发动机" id="engine2">  </td>
                        <td>变速箱</td>
                    </tr>
                    <tr>
                        <td><input  class="form-control" placeholder="变速箱" id="transmissionCase2">  </td>
                        <td>车身结构</td>
                        <td><input  class="form-control" placeholder="车身结构" id="bodyStructure2">  </td>
                        <td>长宽高</td>
                        <td><input  class="form-control" placeholder="长宽高" id="lWH2">  </td>
                        <td>轴距</td>
                        <td><input  class="form-control" placeholder="轴距" id="wheelbase2">  </td>
                        <td>行李箱容积</td>
                    </tr>
                        <td><input  class="form-control" placeholder="行李箱容积" id="cargoVolume2">  </td>
                        <td>整备质量</td>
                        <td><input  class="form-control" placeholder="整备质量" id="curbWeight2">  </td>
                        <td>排量</td>
                        <td><input  class="form-control" placeholder="排量" id="displacement2">  </td>
                        <td>进气形式</td>
                        <td><input  class="form-control" placeholder="进气形式" id="airIntakeForm2">  </td>
                        <td>气缸数</td>
                    <tr>
                        <td><input  class="form-control" placeholder="气缸数" id="numberOfCylinders2">  </td>
                        <td>最大马力</td>
                        <td><input  class="form-control" placeholder="最大马力" id="maximumHorsepower2">  </td>
                        <td>驱动方式</td>
                        <td><input  class="form-control" placeholder="驱动方式" id="drivingMode2">  </td>
                        <td>助力类型</td>
                        <td><input  class="form-control" placeholder="助力类型" id="typesOfAssistance2">  </td>
                        <td>驱车制动类型</td>
                    </tr>
                    <tr>
                        <td><input  class="form-control" placeholder="驱车制动类型" id="drivingBrakeType2">  </td>
                        <td>胎压监测</td>
                        <td><input  class="form-control" placeholder="胎压监测" id="tirePressureDetection2">  </td>
                        <td>前轮胎规格</td>
                        <td><input  class="form-control" placeholder="前轮胎规格" id="frontTireSpecifications2">  </td>
                        <td>后轮胎规格</td>
                    </tr>
                    <tr>
                        <td><input  class="form-control" placeholder="后轮胎规格" id="rearTireSize2">  </td>
                        <td>防抱死</td>
                        <td><input  class="form-control" placeholder="防抱死" id="abs2">  </td>
                        <td>汽车Id</td>
                        <td><input  class="form-control" placeholder="汽车Id" id="carId2">  </td>
                        <td>描述</td>
                        <td><input  class="form-control" placeholder="描述" id="carDesc2">  </td>
                    </tr>
                </table>

            </div>
            <div class="modal-footer">
                <button class="btn btn-success" data-dismiss="modal" aria-hidden="true" onclick="updateData()">保存</button>
                <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">关闭</button>
            </div>
        </div>
    </div>
</div>

</body>
<script type="text/javascript">
    $(function () {
        getData();
    });

    function getData() {
        $.ajax({
            url: "/carinfo/getCarInfoList",
            type: "get",
            data: {},
            dataType: "json",
            async: false,
            success: function (result) {
                if(result.code == 200){
                    var list = result.data;
                    var info = '';
                    $(list).each(function (i,e) {
                        info +='<tr>';
                        info +='<td><input  type="checkbox" name="box" value="'+e.id+'"></td>';
                        info +='<td>'+e.id+'</td>';
                        info +='<td>'+e.manufacturer+'</td>';
                        info +='<td>'+e.level+'</td>';
                        info +='<td>'+e.engine+'</td>';
                        info +='<td>'+e.transmissionCase+'</td>';
                        info +='<td>'+e.bodyStructure+'</td>';
                        info +='<td>'+e.lWH+'</td>';
                        info +='<td>'+e.wheelbase+'</td>';
                        info +='<td>'+e.cargoVolume+'</td>';
                        info +='<td>'+e.curbWeight+'</td>';
                        info +='<td>'+e.displacement+'</td>';
                        info +='<td>'+e.numberOfCylinders+'</td>';
                        info +='<td>'+e.maximumHorsepower+'</td>';
                        info +='<td>'+e.drivingMode+'</td>';
                        info +='<td>'+e.typesOfAssistance+'</td>';
                        info +='<td>'+e.drivingBrakeType+'</td>';
                        info +='<td>'+e.tirePressureDetection+'</td>';
                        info +='<td>'+e.frontTireSpecifications+'</td>';
                        info +='<td>'+e.rearTireSize+'</td>';
                        info +='<td>'+e.abs+'</td>';
                        info +='<td>'+e.carId+'</td>';
                        info +='<td>'+e.carDesc+'</td>';
                        info +='<td class="text-center">';
                        info +='<button type="button" class="btn bg-olive btn-xs" data-toggle="modal" data-target="#editModal2" onclick="toUpdate('+e.id+')">修改</button>';
                        info +='</td>';
                        info +='</tr>';
                    });
                    $("#cate").html(info);
                    //window.location.reload();
                }

            },
            error: function () {
                alert("系统异常,请联系管理员");
            }
        })
    }



    function addData() {
        $.ajax({
            url: "/carinfo/saveCarInfo",
            type: "post",
            contentType: 'application/json; charset=UTF-8',
            data: JSON.stringify({
                manufacturer :$("#manufacturer").val(),brandId :$("#brandId").val(),
                level :$("#level").val(),engine :$("#engine").val(),
                transmissionCase :$("#transmissionCase").val(),bodyStructure :$("#bodyStructure").val(),
                lWH :$("#lWH").val(),wheelbase :$("#wheelbase").val(),
                cargoVolume :$("#cargoVolume").val(),curbWeight :$("#curbWeight").val(),
                displacement :$("#displacement").val(),airIntakeForm :$("#airIntakeForm").val(),
                numberOfCylinders :$("#numberOfCylinders").val(),maximumHorsepower :$("#maximumHorsepower").val(),
                drivingMode :$("#drivingMode").val(),typesOfAssistance :$("#typesOfAssistance").val(),
                drivingBrakeType :$("#drivingBrakeType").val(),tirePressureDetection :$("#tirePressureDetection").val(),
                frontTireSpecifications :$("#frontTireSpecifications").val(),rearTireSize :$("#rearTireSize").val(),
                abs :$("#abs").val(),carId :$("#carId").val(),carDesc :$("#carDesc").val()
            }),
            dataType: "json",
            async: true,
            success: function (result) {
                if(result.code == 200){
                    window.location.reload();
                }

            },
            error: function () {
                alert("系统异常,请联系管理员");
            }
        })

    }

    //修改回显
    function toUpdate(id) {
        $.ajax({
            url: "/carinfo/toUpdate/"+id,
            type: "post",
            data: {},
            dataType: "json",
            async: false,
            success: function (result) {
                if(result.code == 200){
                    var cate = result.data;
                    $("#id").val(cate.id);
                    $("#manufacturer2").val(cate.manufacturer), $("#brandId2").val(cate.brandId),
                        $("#level2").val(cate.level),$("#engine2").val(cate.engine),
                        $("#transmissionCase2").val(cate.transmissionCase),$("#bodyStructure2").val(cate.bodyStructure),
                        $("#lWH2").val(cate.lWH), $("#wheelbase").val(cate.wheelbase),
                        $("#cargoVolume2").val(cate.cargoVolume), $("#curbWeight2").val(cate.curbWeight),
                        $("#displacement2").val(cate.displacement),$("#airIntakeForm2").val(cate.airIntakeForm),
                        $("#numberOfCylinders2").val(cate.numberOfCylinders), $("#maximumHorsepower2").val(cate.maximumHorsepower),
                        $("#drivingMode2").val(cate.drivingMode), $("#typesOfAssistance2").val(cate.typesOfAssistance),
                        $("#drivingBrakeType2").val(cate.drivingBrakeType),$("#tirePressureDetection2").val(cate.tirePressureDetection),
                        $("#frontTireSpecifications2").val(cate.frontTireSpecifications),$("#rearTireSize2").val(cate.rearTireSize),
                        $("#abs2").val(cate.abs),$("#carId2").val(cate.carId),$("#carDesc2").val(cate.carDesc)
                }
            },
            error: function () {
                alert("系统异常,请联系管理员");
            }
        })
    }



    function updateData() {
        $.ajax({
            url: "/carinfo/updateCarInfo",
            type: "post",
            contentType: 'application/json; charset=UTF-8',
            data: JSON.stringify({
                id: $("#id").val(),
                manufacturer :$("#manufacturer2").val(),brandId :$("#brandId2").val(),
                level :$("#level2").val(),engine :$("#engine2").val(),
                transmissionCase :$("#transmissionCase2").val(),bodyStructure :$("#bodyStructure2").val(),
                lWH :$("#lWH2").val(),wheelbase :$("#wheelbase2").val(),
                cargoVolume :$("#cargoVolume2").val(),curbWeight :$("#curbWeight2").val(),
                displacement :$("#displacement2").val(),airIntakeForm :$("#airIntakeForm2").val(),
                numberOfCylinders :$("#numberOfCylinders2").val(),maximumHorsepower :$("#maximumHorsepower2").val(),
                drivingMode :$("#drivingMode2").val(),typesOfAssistance :$("#typesOfAssistance2").val(),
                drivingBrakeType :$("#drivingBrakeType2").val(),tirePressureDetection :$("#tirePressureDetection2").val(),
                frontTireSpecifications :$("#frontTireSpecifications2").val(),rearTireSize :$("#rearTireSize2").val(),
                abs :$("#abs2").val(),carId :$("#carId2").val(),carDesc :$("#carDesc2").val()
            }),
            dataType: "json",
            async: true,
            success: function (result) {
                if(result.code == 200){
                    window.location.reload();
                }
            },
            error: function () {
                alert("系统异常,请联系管理员");
            }
        })
    }

    function deleteBatch() {
        var ids = [];
        $("[name=box]:checked").each(function (i,e) {
            ids.push(e.value);
        });

        if(ids.length <= 0){
            alert("请选择需要删除的行");
            return;
        }

        $.ajax({
            url:"/carinfo/deleteBatch/"+ids,
            type : "post",
            data:{},
            dataType : "json",
            async : false,//同步
            success : function(result) {
                if(result.code == 200){
                    window.location.reload();
                }
            },
            error : function() {
                alert("系统异常,请联系管理员");
            }
        })

    }
</script>
</html>